#include "stdafx.hpp"
#include "ColligereUtils.hpp"
#include "ColligereXmlUtils.hpp"

const wxString col::XmlUtils::GetNodeContent ( const wxXmlNode *pNode )
{
	return pNode ? pNode->GetNodeContent() : empty_string;
}

const wxString col::XmlUtils::GetNodeContent
( const wxXmlNode *pRoot, const wxString &rName )
{
	return GetNodeContent ( FindNode ( pRoot, rName ) );
}

const wxString col::XmlUtils::GetNodeAttribute
( const wxXmlNode *pNode, const wxString &rPropName )
{
	return pNode ? pNode->GetAttribute ( rPropName, empty_string ) : empty_string;
}


const wxXmlNode *col::XmlUtils::FindNode
( const wxXmlNode *pParent, const wxString &rName )
{
	boost::scoped_ptr < wxxml_tree_adapter<> > ta 
		( new  wxxml_tree_adapter<> );
	return find_first_child_node < const wxXmlNode * > ( rName, pParent, *ta );
}

const col::XmlUtils::XmlNodePtrDeque 
col::XmlUtils::FindNodes ( const wxXmlNode *pParent, const wxString &rName )
{
	wxASSERT ( pParent );

	std::deque < const wxXmlNode * > ret;
	boost::scoped_ptr < wxxml_tree_adapter<> > ta ( new  wxxml_tree_adapter<> );
	search_nodes < const wxXmlNode * > ( rName, pParent, ret, *ta );

	return ret;
}

wxUint32 col::XmlUtils::GetItemCount 
( const wxXmlDocument &rFromDoc, const wxString &rNodeName )
{
	const wxXmlNode *root ( rFromDoc.GetRoot() );

	wxASSERT ( root );

	if ( root )
	{
		std::deque < const wxXmlNode * > ret;
		boost::scoped_ptr < wxxml_tree_adapter<> > ta ( new wxxml_tree_adapter<> );
		return search_nodes < const wxXmlNode * > ( rNodeName, root, ret, *ta );
	}
	return 0;
}